package com.nd.android.musicboxlibrary.ui.common;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.common.utils.StarAppUtils;
import com.nd.android.musicboxlibrary.R;

/**
 * 页面模板
 * 
 * @author 慕容秋 (muroqiu@qq.com)
 */
public class BaseFragmentActivity extends FragmentActivity implements OnClickListener {

    protected TextView txtTitle;

    protected ImageButton btnLeft;

    protected ImageView btnRight;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    /**
     * 设置标题右边按钮图片
     * 
     * @param iconResouce
     *            图片资源
     */
    protected void setRightButton(int iconResouce) {
        if (iconResouce > 0) {
            btnRight.setImageResource(iconResouce);
            btnRight.setVisibility(View.VISIBLE);
        } else {
            btnRight.setVisibility(View.INVISIBLE);
        }
    }

    /**
     * 
     * <br>
     * Created 2014年9月15日 下午11:12:30
     * 
     * @param iconResouce int
     * @author wat.ztag
     */
    protected void setLeftButton(int iconResouce) {
        if (iconResouce > 0) {
            btnLeft.setImageResource(iconResouce);
            btnLeft.setVisibility(View.VISIBLE);
        } else {
            btnLeft.setVisibility(View.INVISIBLE);
        }
    }

    @Override
    public void onContentChanged() {
        super.onContentChanged();
        btnLeft = (ImageButton) this.findViewById(R.id.btnLeft);
        txtTitle = (TextView) this.findViewById(R.id.txtTitle);

        btnRight = (ImageView) this.findViewById(R.id.btnRight);
        if (btnLeft != null) {
            btnLeft.setOnClickListener(this);
        }

        if (btnRight != null) {
            btnRight.setOnClickListener(this);
        }

        StarAppUtils.setViewTypeFace(txtTitle, true);
    }

    @Override
    public void onStart() {
        super.onStart();
    }

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    /*
     * (non-Javadoc)
     * 
     * @see android.app.Activity#onDestroy()
     */
    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }

    /**
     * 恢复时执行 context定位工作
     * @param inState Bundle
     */
    @Override
    protected void onRestoreInstanceState(Bundle inState) {
        super.onRestoreInstanceState(inState);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    public void overridePendingTransition(int enterAnim, int exitAnim) {
        super.overridePendingTransition(enterAnim, exitAnim);
    }

    /**
     * 
     * <br>
     * Created 2014年9月15日 下午11:12:33
     * 
     * @author wat.ztag
     */
    protected void initData() {

    }

    @Override
    public void onClick(View v) {
        int viewId = v.getId();
        if (viewId == R.id.btnLeft) {
            onBackPressed();
        }
    }
}
